import request from '@/utils/request'
import type {
  DeleteRequest,
  RoleAddRequest,
  RoleQueryRequest,
  RoleUpdateRequest,
  PageRole,
  RolePermissionAddRequest,
} from './type'
//项目用户相关的请求地址
enum API {
  LIST_URL = '/admin/role/list',
  GETALL_URL = '/admin/role/all',
  DELETE_URL = '/admin/role/delete',
  ADD_URL = '/admin/role/add',
  UPDATE_URL = '/admin/role/update',
  DELETE_BATCH_URL = '/admin/role/deleteBatch',
  ROLE_MENU_URL = '/admin/permission/getRoleMenu',
  SAVE_PERMISSION_URL = '/admin/permission/savePermission',
}

//获取所有角色列表接口
export const reqGetAll = () => request.get<any, any>(API.GETALL_URL)

//获取标签列表接口
export const reqList = (data: RoleQueryRequest) =>
  request.post<any, PageRole>(API.LIST_URL, data)

//删除标签接口
export const reqDelete = (data: DeleteRequest) =>
  request.post<any, any>(API.DELETE_URL, data)

//新增标签接口
export const reqAdd = (data: RoleAddRequest) =>
  request.post<any, any>(API.ADD_URL, data)

//修改标签接口
export const reqUpdate = (data: RoleUpdateRequest) =>
  request.post<any, any>(API.UPDATE_URL, data)

export const reqDeleteBatch = (ids: any) =>
  request.post<any, any>(API.DELETE_BATCH_URL, { ids: ids })

//获取角色对应的菜单
export const reqGetRoleMenu = (roleId: number) =>
  request.get<any, any>(API.ROLE_MENU_URL, { params: { roleId } })

//保存权限接口
export const reqSavePermission = (data: RolePermissionAddRequest) =>
  request.post<any, any>(API.SAVE_PERMISSION_URL, data)
